let _debounceTimeout = null,
	_throttleRunning = false

/**
 * 防抖
 * @param {Function} 执行函数
 * @param {Number} delay 延时ms
 */
export const debounce = (fn, delay=500) => {
	clearTimeout(_debounceTimeout);
	_debounceTimeout = setTimeout(() => {
		fn();
	}, delay);
}
/**
 * 节流
 * @param {Function} 执行函数
 * @param {Number} delay 延时ms
 */
export const throttle = (fn, delay=500) => {
	if(_throttleRunning){
		return;
	}
	_throttleRunning = true;
	fn();
	setTimeout(() => {
	    _throttleRunning = false;
	}, delay);
}
/**
 * toast
 */
export const msg = (title = '', param={}) => {
	if(!title) return;
	uni.showToast({
		title,
		duration: param.duration || 1500,
		mask: param.mask || false,
		icon: param.icon || 'none'
	});
}
/**
 * 小程序检查登录
 * @return {Boolean}
 */
export const isLogin = (options={}) => {
	const uid = uni.getStorageSync('uid');
	if(uid){
		return true;
	}
	uni.reLaunch({
		url: '/pages/auth/wxrole'
	})
	return false;
}


/**
 * 抖音检查登录
 * @return {Boolean}
 */
export const douisLogin = (options={}) => {
	let url = location.href;
	let requestParams = {};
		if (url.indexOf("?") !== -1) {
		let str = url.substr(url.indexOf("?") + 1); //截取?后面的内容作为字符串
		console.log(str,'?后面的内容');
		let strs = str.split("&"); //将字符串内容以&分隔为一个数组
		console.log(strs,'以&切割的数组');
		for (let i = 0; i < strs.length; i++) {
		  requestParams[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
		}
	}
	const params = requestParams;
	const code= params["code"];
	const uid = uni.getStorageSync('uid');
	if (!code && !uid) {
		const url_web = window.location.href;
		const wxurl = "https://open.douyin.com/platform/oauth/connect/?client_key=awkager18ntenck6&response_type=code&scope=user_info,mobile,video.create&redirect_uri="+url_web+"&state=test";
		window.location.href = wxurl;
		return;
	}
	return true;
}
